<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Predicates (GNU Compiler Collection (GCC) Internals)</title>

<meta name="description" content="Predicates (GNU Compiler Collection (GCC) Internals)">
<meta name="keywords" content="Predicates (GNU Compiler Collection (GCC) Internals)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Option-Index.html" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Machine-Desc.html" rel="up" title="Machine Desc">
<link href="Constraints.html" rel="next" title="Constraints">
<link href="Output-Statement.html" rel="prev" title="Output Statement">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
span:hover a.copiable-link {visibility: visible}
-->
</style>


</head>

<body lang="en">
<div class="section-level-extent" id="Predicates">
<div class="nav-panel">
<p>
Next: <a href="Constraints.html" accesskey="n" rel="next">Operand Constraints</a>, Previous: <a href="Output-Statement.html" accesskey="p" rel="prev">C Statements for Assembler Output</a>, Up: <a href="Machine-Desc.html" accesskey="u" rel="up">Machine Descriptions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h3 class="section" id="Predicates-1"><span>17.7 Predicates<a class="copiable-link" href="#Predicates-1"> &para;</a></span></h3>
<a class="index-entry-id" id="index-predicates"></a>
<a class="index-entry-id" id="index-operand-predicates"></a>
<a class="index-entry-id" id="index-operator-predicates"></a>

<p>A predicate determines whether a <code class="code">match_operand</code> or
<code class="code">match_operator</code> expression matches, and therefore whether the
surrounding instruction pattern will be used for that combination of
operands.  GCC has a number of machine-independent predicates, and you
can define machine-specific predicates as needed.  By convention,
predicates used with <code class="code">match_operand</code> have names that end in
&lsquo;<samp class="samp">_operand</samp>&rsquo;, and those used with <code class="code">match_operator</code> have names
that end in &lsquo;<samp class="samp">_operator</samp>&rsquo;.
</p>
<p>All predicates are boolean functions (in the mathematical sense) of
two arguments: the RTL expression that is being considered at that
position in the instruction pattern, and the machine mode that the
<code class="code">match_operand</code> or <code class="code">match_operator</code> specifies.  In this
section, the first argument is called <var class="var">op</var> and the second argument
<var class="var">mode</var>.  Predicates can be called from C as ordinary two-argument
functions; this can be useful in output templates or other
machine-specific code.
</p>
<p>Operand predicates can allow operands that are not actually acceptable
to the hardware, as long as the constraints give reload the ability to
fix them up (see <a class="pxref" href="Constraints.html">Operand Constraints</a>).  However, GCC will usually generate
better code if the predicates specify the requirements of the machine
instructions as closely as possible.  Reload cannot fix up operands
that must be constants (&ldquo;immediate operands&rdquo;); you must use a
predicate that allows only constants, or else enforce the requirement
in the extra condition.
</p>
<a class="index-entry-id" id="index-predicates-and-machine-modes"></a>
<a class="index-entry-id" id="index-normal-predicates"></a>
<a class="index-entry-id" id="index-special-predicates"></a>
<p>Most predicates handle their <var class="var">mode</var> argument in a uniform manner.
If <var class="var">mode</var> is <code class="code">VOIDmode</code> (unspecified), then <var class="var">op</var> can have
any mode.  If <var class="var">mode</var> is anything else, then <var class="var">op</var> must have the
same mode, unless <var class="var">op</var> is a <code class="code">CONST_INT</code> or integer
<code class="code">CONST_DOUBLE</code>.  These RTL expressions always have
<code class="code">VOIDmode</code>, so it would be counterproductive to check that their
mode matches.  Instead, predicates that accept <code class="code">CONST_INT</code> and/or
integer <code class="code">CONST_DOUBLE</code> check that the value stored in the
constant will fit in the requested mode.
</p>
<p>Predicates with this behavior are called <em class="dfn">normal</em>.
<code class="command">genrecog</code> can optimize the instruction recognizer based on
knowledge of how normal predicates treat modes.  It can also diagnose
certain kinds of common errors in the use of normal predicates; for
instance, it is almost always an error to use a normal predicate
without specifying a mode.
</p>
<p>Predicates that do something different with their <var class="var">mode</var> argument
are called <em class="dfn">special</em>.  The generic predicates
<code class="code">address_operand</code> and <code class="code">pmode_register_operand</code> are special
predicates.  <code class="command">genrecog</code> does not do any optimizations or
diagnosis when special predicates are used.
</p>

<ul class="mini-toc">
<li><a href="Machine_002dIndependent-Predicates.html" accesskey="1">Machine-Independent Predicates</a></li>
<li><a href="Defining-Predicates.html" accesskey="2">Defining Machine-Specific Predicates</a></li>
</ul>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Constraints.html">Operand Constraints</a>, Previous: <a href="Output-Statement.html">C Statements for Assembler Output</a>, Up: <a href="Machine-Desc.html">Machine Descriptions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
